<script type="text/javascript">
<html>
<head>
<script type="text/javascript">
function showUser(str)
{
if (str=="")
  {
  document.getElementById("txtHint").innerHTML="";
  return;
  } 
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","getuser.php?q="+str,true);
xmlhttp.send();
}
</script>
<head>
<script type="text/javascript">
function showUser(str)
{
if (str=="")
  {
  document.getElementById("txtHint").innerHTML="";
  return;
  } 
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","<?php echo Yii::app()->createUrl('admin/questions/show')?>?q="+str,true);
xmlhttp.send();
}
</script>

<div align="right">
<?php 

if(!empty($model->quiz_id))
$url=Yii::app()->createUrl('/admin/questions/admin/id/'.$model->quiz_id);
elseif(!empty($_GET['id'])) 
$url=Yii::app()->createUrl('/admin/questions/admin/id/'.$_GET['id']);
else
$url=Yii::app()->createUrl('/admin/questions/admin');
?>
<a href="<?php echo $url;?>" class="button_design" align="right">Back</a>
</div>
<div class="form">
<?php if(Yii::app()->user->hasFlash('success')){?>
  <div class="flash-success" style="color:black;background-color:#FFFF67;">
     <?php echo Yii::app()->user->getFlash('success');?>

</div>
      <?php } ?>
<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'questions-form',
	'enableAjaxValidation'=>false,
)); ?>
<?php 
$status='published';
$objects = Quiz::model()->findAll('status=? and user_id=?',array($status,Yii::app()->user->id));
$arr = array();
foreach ($objects as $obj) {
     $arr[$obj->id] = $obj->title;
}?>
	

	<?php echo $form->errorSummary($model); ?>
<?php 
if(!empty($_GET))
{
$id=$_GET['id'];
$levels = Quiz::model()->find('id=?',array($id));
}
else 
$id="";

?>
	<div class="row">
		<?php echo $form->labelEx($model,'quiz_id'); ?>
		<?php echo $form->dropDownList($model,'quiz_id',$arr,array('empty'=>'select quiz','onchange'=>"showUser(this.value)",'options'=>array($id=>array('selected'=>'selected')))); ?>
		<?php echo $form->error($model,'quiz_id'); ?>
	</div>
<?php if(!empty($model->quiz_id)){
	$levels = Quiz::model()->find('id=?',array($model->quiz_id));
		
}?>
	<div class="row" >
	<b>Level</b><br/>
	<select name="txtHint" id="txtHint" >
	<?php if(!empty($model->quiz_id)){?>	
	<?php for ($i=1;$i<=$levels->no_of_level;$i++){?>
	
	<option value="<?php echo $i?>" <?php if($model->level==$i){echo "selected";}?>><?php echo $i;?></option>
		<?php }}
		elseif(!empty($_GET))
		{
		for ($i=1;$i<=$levels->no_of_level;$i++){?>
	
	<option value="<?php echo $i?>"><?php echo $i;?></option>
	<?php 	}	
		}?>
	
		</select>
	</div>
	<div class="row">
		<?php echo $form->labelEx($model,'title'); ?>
		<?php echo $form->textField($model,'title',array('size'=>60,'maxlength'=>200)); ?>
		<?php echo $form->error($model,'title'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'description'); ?>
		<?php echo $form->textField($model,'description',array('size'=>60,'maxlength'=>500)); ?>
		<?php echo $form->error($model,'description'); ?>
	</div>


	<?php

//Image URL
$delete_path="/clients/quize/images/delete.png";
$add_more_path="/eduapp/images/link/add_quiz.png";
?>

<?php 
//echo '<b>Managing options for <u> '.Questions::model()->findByPk($id)->title.'</u> question</b>'; 
?>

<?php //echo '<pre>';print_r($default);exit;
	$count=0;
	
?>
<br/>
<H3>Enter options</H3>
<div style="border: 3px grey solid;border-radius: 19px;">

<table style="padding-left: 4%;padding-top: 1%;">
<tr><th>Options</th><th>correct answer</th><th>Action</th></tr>
<?php foreach($items as $i=>$item): 
?>
<tr>

<td><?php echo CHtml::activeTextArea($item,"[$i]name"); ?></td>
<td>
<?php 
$newarray=array();
$selected = null;


if($item->correct_option=='yes')
{
	$selected="checked";
	
	 echo CHtml::activeRadioButton($item,"[$i]correct_option",array('checked' =>$selected,"id"=>"[$i]correct_option", "onclick"=>'setoption("['.$i.']correct_option")'));
}
else 
{	
	echo CHtml::activeRadioButton($item,"[$i]correct_option",array("id"=>"[$i]correct_option",'onclick'=>'setoption("['.$i.']correct_option")'));
}?>
</td>
<?php //echo CHtml::link(CHtml::image("$delete_path","Delete",''),array('Options/remove',"id"=>$item->id)) ?>
<td>
<?php echo CHtml::ajaxLink(
	    CHtml::image("$delete_path","Delete",''),          // the link body (it will NOT be HTML-encoded.)
	    Yii::app()->createUrl( 'admin/options/remove/id/'.$item->id ), // the URL for the AJAX request. If empty, it is assumed to be the current URL.
	    array(
	         'success' => "function( data )
                  {
                    window.location.reload();
                  }",
	    	'error' => "function( data )
                  {
                    window.location.reload();
                  }",
	    )
 
); ?>
</td>                    
</tr>

<?php $count++; endforeach; ?>

</table>

<script type="text/javascript">
function setoption($id)
{
	
	for(var i=0;i<10;i++)
	{
		var name1="["+i+"]correct_option";	

		if(document.getElementById(name1))
			document.getElementById(name1).checked=false;
		
	}
	document.getElementById($id).checked="checked";

}
</script>
	
	
	
	
	
	
	
	
	
	<div class="row" style="padding-left: 4%;padding-bottom: 1%;">
		<?php echo $form->labelEx($model,'correct_answer_desc'); ?>
		<?php echo $form->textArea($model,'correct_answer_desc',array('rows'=>6, 'cols'=>50)); ?>
		<?php echo $form->error($model,'correct_answer_desc'); ?>
	</div>
</div>
<br/>
	<div class="row">
		<?php echo $form->labelEx($model,'status'); ?>
		 <?php echo $form->dropDownList($model,'status', array('draft'=>'draft','published'=>'published')); ?>
		<?php echo $form->error($model,'status'); ?>
	</div>
	
	<div class="row">
		<?php echo $form->labelEx($model,'points'); ?>
		<?php echo $form->textField($model,'points'); ?>
		<?php echo $form->error($model,'points'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'type'); ?>
		 <?php echo $form->dropDownList($model,'type', array('paid'=>'paid','unpaid'=>'unpaid')); ?>
		<?php echo $form->error($model,'type'); ?>
	</div>
	<div class="row buttons">
		<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
		
	</div>

<?php $this->endWidget(); ?>

</div><!-- form -->

